import subprocess
from PIL import Image


class GameCapturer:
    def __init__(self, device_id='emulator-5554'):
        self.device_id = device_id
        self.base_resolution = (1080, 1920)  # 基准分辨率

    def capture_screen(self):
        """通过ADB获取屏幕截图"""
        subprocess.run(f'adb -s {self.device_id} exec-out screencap -p > screen.png',
                       shell=True)
        return Image.open('screen.png')

    def get_dynamic_resolution(self):
        """获取实时分辨率"""
        output = subprocess.check_output(
            f'adb -s {self.device_id} shell wm size',
            shell=True
        ).decode()
        return tuple(map(int, output.split()[-1].split('x')))